package com.tdkj.service.shop.impl;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.tdkj.dao.shop.IBeanMallNoticeDao;
import com.tdkj.model.shop.BeanMallNotice;
import com.tdkj.model.user.BeanUser;
import com.tdkj.service.BaseService;
import com.tdkj.service.shop.IBeanMallNoticeService;

@Component
public class BeanMallNoticeServiceImpl extends BaseService implements
		IBeanMallNoticeService {
	
	private  IBeanMallNoticeDao beanMallNoticeDao;
    
	@Resource
	public void setBeanMallNoticeDao(IBeanMallNoticeDao beanMallNoticeDao) {
		this.beanMallNoticeDao = beanMallNoticeDao;
	}


	@Override
	public BeanMallNotice add(String title, String content, Long userId) {
		BeanUser user = beanMallNoticeDao.findById(userId, BeanUser.class);
		BeanMallNotice bean = new BeanMallNotice();
		bean.setTitle(title);
		bean.setUser(user);
		bean.setContent(content);
		bean.setPublishTime(new Date(System.currentTimeMillis()));
		beanMallNoticeDao.save(bean);
		return bean;
	}

	@Override
	public void update(Long id, String title, String content, Long userId) {
		BeanUser user = beanMallNoticeDao.findById(userId, BeanUser.class);
		BeanMallNotice bean = beanMallNoticeDao.findById(id, BeanMallNotice.class);
		bean.setTitle(title);
		bean.setUser(user);
		bean.setContent(content);
		bean.setPublishTime(new Date(System.currentTimeMillis()));
	}

}
